<?php
namespace app\common\model;
use think\Model;

class StaffModel extends Model{
    protected  $name = 'staff';
    protected  $pk   = 'staff_id';

    public static function onBeforeInsert($model)
    {
        $model->set("create_ip", request()->ip());
    }

    public function detail(){
        return $this->hasOne(StaffDetailModel::class,'staff_id','staff_id')->bind([
            'name_en',
            'position_en',
            'weixin',
            'wx_qr',
            'mail',
            'spare1',
            'spare2',
            'is_card',
            'card',
            'face',
            'tag',
            'is_share',
            'share_text',
            'share_image',
        ]);
    }

    public function profile(){
        return $this->hasOne(StaffProfileModel::class,'staff_id','staff_id')->bind(['profile_type','profile_text']);
    }
    
    public function firm(){
        return $this->hasOne(FirmDetailModel::class,'firm_id','firm_id')->bind(['company_name','tel','address','info','lat','lng']);
    }
    
    public function style(){
        return $this->hasOne(FirmStyleModel::class,'firm_id','firm_id');
    }
    
    public function custom(){
        return $this->hasOne(StaffProfileModel::class,'staff_id','staff_id')->bind(['profile_custom','profile_type','profile_text']);
    }
}
